/*************************************************************************
	> File Name: sigcount.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sat 21 Jun 2014 02:20:27 PM CST
 ************************************************************************/

#include<stdio.h>
#include<unistd.h>
#include<signal.h>
int count=0;
void dealing(int sig)
{
    printf("\e[44m cought the signal\e[0m\n");
    if(sig==SIGTERM)
    {
        count++;
    }
    printf("have reviced signal SIGTERM for\e[42m %d \e[0mtimes\n",count);
}

int main(int argc, char *argv[])
{
    struct sigaction sa;
    sigset_t set;

    if(sigfillset(&set)==-1)
    {
        perror("sigempty:");
        raise(2);
    }

   /* if(sigaddset(&set,SIGTERM)==-1)
    {
        perror("sigaddset:");
        raise(2);
    }
    */

    sa.sa_handler=dealing;
    sa.sa_mask=set;
    sa.sa_flags=SA_RESTART;

    if(sigaction(SIGTERM,&sa,NULL)==-1)
    {
        perror("sigaction:");
        raise(2);
    }

    int i;
    for(i=0;;i++)
        pause();
}
